//
//  SISSLinesTextShowViewController.m
//  SISSAPP
//
//  Created by 袁应荣 on 2018/4/10.
//  Copyright © 2018年 优房网. All rights reserved.
//

#import "SISSLinesTextShowViewController.h"

@interface SISSLinesTextShowViewController ()

@end

@implementation SISSLinesTextShowViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.sectionTitles.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *reuseID = @"ID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseID];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseID];
        
        cell.textLabel.font = [UIFont systemFontOfSize:15];
        cell.textLabel.textColor = MAIN_TEXT_COLOR;
        cell.textLabel.numberOfLines = 0;
        CGFloat margin = 8.0;
        [cell.textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(cell.contentView).offset(0.5 * margin);
            make.left.right.equalTo(cell.contentView).offset(margin);
            make.right.equalTo(cell.contentView).offset(-margin);
            make.bottom.equalTo(cell.contentView).offset(-2 * margin);
        }];
    };
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.textLabel.text = self.dataSource[indexPath.section];
    
    return cell;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    UILabel *label = [UILabel yyr_labelWithText:self.sectionTitles.count == self.dataSource.count ? self.sectionTitles[section] : @"" fontSize:17 textColor:MAIN_TEXT_COLOR];
    [view addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(view).offset(16);
        make.centerY.equalTo(view);
    }];
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return ((NSString *)self.sectionTitles[section]).length > 0 ? 44 : 0;
}

/// 取消tableView组头悬停
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGFloat sectionHeaderHeight = 44;
    if (scrollView.contentOffset.y <= sectionHeaderHeight && scrollView.contentOffset.y >= 0) {
        scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
    } else if (scrollView.contentOffset.y >= sectionHeaderHeight) {
        scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
